# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gtksourceview

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}3"
pkgver=3.12.1
pkgrel=1
pkgdesc="A text widget adding syntax highlighting and more to GNOME (mingw-w64)"
arch=('any')
url="http://www.gnome.org"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
    "${MINGW_PACKAGE_PREFIX}-pkg-config"
    "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
    "${MINGW_PACKAGE_PREFIX}-glade"
    "intltool")
depends=(
    "${MINGW_PACKAGE_PREFIX}-gtk3"
    "${MINGW_PACKAGE_PREFIX}-libxml2")
options=(!libtool strip staticlibs)
source=("http://ftp.gnome.org/pub/gnome/sources/gtksourceview/${pkgver%.*}/gtksourceview-${pkgver}.tar.xz"
    0004-give-cc-to-gir-scanner.all.patch
    0005-give-gtk-cflags-to-gir.patch)
md5sums=('4012b31fc2d06d18da1e9588312ac97e'
         '58bab414c041519201a82b2b830741d1'
         '225318992810922513325ccd8e408e13')

prepare() {
  cd ${_realname}-$pkgver
  patch -p1 -i ${srcdir}/0004-give-cc-to-gir-scanner.all.patch
  patch -p1 -i ${srcdir}/0005-give-gtk-cflags-to-gir.patch
  autoreconf -fi
}

build() {
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  DATADIRNAME=share \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --disable-static \
    --enable-glade-catalog
  LC_ALL=en_US.UTF-8 make -j1 V=1
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 DESTDIR="$pkgdir" install
  
  for ff in ${pkgdir}/${MINGW_PREFIX}/bin/libgtksourceview*.dll; do
    local _reallib=$(basename $ff)
    _reallib=${_reallib%.dll}
    _reallib=${_reallib#lib}
    sed -e "s|library=\"gtksourceview-3.0\"|library=\"${_reallib}\"|g" -i ${pkgdir}/${MINGW_PREFIX}/share/glade/catalogs/gtksourceview.xml
  done
}
